package tmt.usercenter.web.repository;


import com.tmt.jpa.jpaservice.ITmtBaseRepo;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import tmt.usercenter.web.domain.SmHistory;
import tmt.usercenter.web.domain.enums.FuncPointType;

import java.util.Date;

public interface ISmHistoryRepo extends ITmtBaseRepo<SmHistory, Long> {

    SmHistory findById(Long id);

    SmHistory findFirstByToMobileOrderByCreateTimeDesc(String toMobile);

    SmHistory findFirstByToMobileAndFuncPointAndValidOrderByIdDesc(String toMobile, FuncPointType funcPoint, boolean valid);

    @Query("select count(t) from SmHistory t where t.smStatus = tmt.usercenter.web.domain.enums.SmStatus.SEND_SUCCESS " +
            "and t.funcPoint = :funcPoint and t.toMobile =:mobile " +
            "and t.createTime > :curDate")
    int countByFuncPointAndToMobileAndSmStatus(@Param("funcPoint") FuncPointType funcPoint,
                                               @Param("mobile") String mobile,
                                               @Param("curDate") Date curDate);

}
